package com.endoc.plugin

import com.android.builder.model.SigningConfig;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;

//不能用public,具体为啥我也不知道
class JiaguTask extends DefaultTask {

    //构造函数
    JiaguTask(){
        //设置当前任务分组,会在右边的Gradle处显示这个分组
        group ="jiagu"
    }



    Jiagu jiagu
    SigningConfig signingConfig
    File apk

    @TaskAction
    def run() {
        //执行命令行的api
        project.exec {//闭包
            //it是这个exec中提供的一个对象
            //执行 java -jar jiagu.jar -login user password,登录命令
            it.commandLine("java", "-jar", jiagu.jiaguTools, "-login", jiagu.userName, jiagu.password)
        }

        if (signingConfig) {//如果配置了证书
            project.exec {
                //执行java -jar jiagu.jar -importsign 参数,证书路径,
                it.commandLine("java", "-jar", jiagu.jiaguTools, "-importsign", signingConfig.storeFile.absolutePath,
                        signingConfig.storePassword, signingConfig.keyAlias, signingConfig.keyPassword)
            }
        }

        //加固
        project.exec {
            //-jiagu <inputAPKpath> 			加固命令 <APK路径>
            it.commandLine("java", "-jar", jiagu.jiaguTools, "-jiagu", apk.absolutePath,apk.parent,"-autosign")
        }
    }
}
